<?php

class StateAction extends ActionBase {
	public $modelName;
	public $nextState;
	public $stateHandle = 'stateHandle';
	
	public function run($id) {
		$c = $this->controller;
		$modelName = $this->modelName;
		$model = new $modelName();
		$model = $model->findByAttributes(array(
			'id' => $id,
			'worker_id' => Yii::app()->adminUser->id
		));
		if (!is_object($model)) $c->redirect(Yii::app()->createUrl('misc/error404',array('msg'=>'该数据不存在')));
		
		$model->{$this->stateHandle}->setState($this->nextState);
		if($model->getErrors()) {
			Yii::app()->user->setFlash(FLASH::RESULT_FAILED, CHtml::errorSummary($model));
		}
		CControllerHelper::redirectReferrer();
	}
	
}

?>